// const request = (url, method='GET', data='{}', success, fail) => {
//   wx.request({
//     url,
//     method,
//     data,
//     success,
//     fail
//   })
// }
// module.exports = request

import config from './config'
export default (url, data={}, method='GET') => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: config.host + url,
      method,
      data,
      header: {
        'cookie': wx.getStorageSync('cookie') ? wx.getStorageSync('cookie').find(item => item.indexOf('MUSIC_U') != -1): ''
      },
      success: (res) => {
        if (url == '/login/cellphone') {
          wx.setStorage({
            key: 'cookie',
            data: res.cookies
          })
        }
        resolve(res.data)
      },
      fail: (err) => {
        console.log(`%c ${url}失败的回调`, 'color: red', res);
        reject(err)
      }
    })
  })
}